package me.yangteng.zhihudaily.component;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.squareup.picasso.Picasso;

import java.util.List;

import me.yangteng.zhihudaily.R;
import me.yangteng.zhihudaily.model.LatestNews;

/**
 * Created by MorenYang on 2017/12/19.
 */

public class ScrollViewAdapter extends StaticPagerAdapter {
  private List<LatestNews.TopStoriesBean> topStoriesList;
  private Context context;

  public ScrollViewAdapter(List<LatestNews.TopStoriesBean> topStoriesList, Context context) {
    this.topStoriesList = topStoriesList;
    this.context = context;
  }

  @Override
  public View getView(ViewGroup container, int position) {

    LayoutInflater layoutInflater = LayoutInflater.from(container.getContext());
    View view = layoutInflater.inflate(R.layout.view_pager_layout, null);

    ImageView bannerImage = view.findViewById(R.id.viewPagerBannerImage);
    TextView bannerTitle = view.findViewById(R.id.viewPagerBannerTitle);
    bannerTitle.setText(topStoriesList.get(position).getTitle());
    Picasso.with(context)
      .load(topStoriesList.get(position).getImage())
      .into(bannerImage);
    return view;
  }

  @Override
  public int getCount() {
    return this.topStoriesList.size();
  }
}
